<template>
  <view class="uni-goods-nav">
    <!-- 底部占位 -->
    <view class="uni-tab__seat" />
    <view class="uni-tab__cart-box flex">
      <view class="flex uni-tab__cart-sub-box">
        <view
          v-for="(item, index) in options"
          :key="index"
          class="flex uni-tab__cart-button-left uni-tab__cart-item"
        >
          <view class="uni-tab__icon">
            <image class="image" :src="item.icon" mode="widthFix" />
          </view>
          <text class="uni-tab__text">{{ item.text }}</text>
          <view class="flex uni-tab__dot-box">
            <text
              v-if="item.info"
              :class="{ 'uni-tab__dots': item.info > 9 }"
              class="uni-tab__cart-dot"
            >{{ item.info > 9 ? '9+' : item.info }}</text>
          </view>
        </view>
      </view>
      <view :class="{ 'uni-tab__right': fill }" class="flex uni-tab__cart-sub-box">
        <view
          v-for="(item, index) in buttonGroup"
          :key="index"
          :style="{ backgroundColor: item.backgroundColor, color: item.color }"
          class="flex uni-tab__cart-button-right"
          @click="buttonClick(index, item)"
        >
          <text class="uni-tab__button-text">{{ item.text }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'UniGoodsNav',
  props: {
    options: {
      type: Array,
      default: () => []
    },
    buttonGroup: {
      type: Array,
      default: () => []
    },
    fill: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    buttonClick(index, item) {
      this.$emit('buttonClick', { index, item });
    }
  }
};
</script>

<style scoped>
.uni-goods-nav {
  position: relative;
  z-index: 99;
}
.uni-tab__seat {
  height: 100rpx;
}
.uni-tab__cart-box {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100rpx;
  background-color: #fff;
  border-top: 1px solid #eee;
  align-items: center;
}
.flex {
  display: flex;
  align-items: center;
}
.uni-tab__cart-sub-box {
  height: 100%;
}
.uni-tab__cart-button-left {
  padding: 0 20rpx;
  height: 100%;
  justify-content: center;
}
.uni-tab__icon .image {
  width: 40rpx;
  height: 40rpx;
}
.uni-tab__text {
  font-size: 24rpx;
  margin-left: 10rpx;
}
.uni-tab__dot-box {
  margin-left: 10rpx;
}
.uni-tab__cart-dot {
  display: inline-block;
  min-width: 30rpx;
  height: 30rpx;
  line-height: 30rpx;
  text-align: center;
  background-color: #f53f3f;
  color: #fff;
  font-size: 20rpx;
  border-radius: 15rpx;
}
.uni-tab__dots {
  text-indent: -2rpx;
}
.uni-tab__right {
  flex: 1;
  justify-content: flex-end;
}
.uni-tab__cart-button-right {
  height: 80rpx;
  padding: 0 30rpx;
  margin-right: 20rpx;
  border-radius: 40rpx;
  justify-content: center;
}
.uni-tab__button-text {
  font-size: 28rpx;
}
</style>